<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改教务校区')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-school-edit" th:object="${teachingSchool}">
        <input name="schoolId" th:field="*{schoolId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">学校名称：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{name}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学校简称：</label>
            <div class="col-sm-8">
                <input name="shortName" th:field="*{shortName}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">所属区域：</label>
            <div class="col-sm-8" id="element1">
                <select name="provinceCode" style="width: 120px;float: left"
                        class="province form-control m-b"
                        data-first-title="选择省"
                        data-required="true"
                        th:attrappend="data-value=*{provinceCode}"
                >
                    <option value="">请选择</option>
                </select>
                <select name="cityCode" style="width: 120px;float: left"
                        class="city form-control m-b"
                        data-first-title="选择市"
                        data-required="true"
                        th:attrappend="data-value=*{cityCode}"
                >
                    <option value="">请选择</option>
                </select>
                <select name="areaCode" style="width: 120px;float: left"
                        class="area form-control m-b"
                        data-first-title="选择区域"
                        data-required="true"
                        th:attrappend="data-value=*{areaCode}"
                >
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">详细地址：</label>
            <div class="col-sm-8">
                <input name="address" th:field="*{address}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">加盟时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="joinTime" th:value="${#dates.format(teachingSchool.joinTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">到期时间：</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="allottedTime" th:value="${#dates.format(teachingSchool.allottedTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">负责人：</label>
            <div class="col-sm-8">
                <input name="principal" th:field="*{principal}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">电话：</label>
            <div class="col-sm-8">
                <input name="principalPhone" th:field="*{principalPhone}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">微信：</label>
            <div class="col-sm-8">
                <input name="principalWechat" th:field="*{principalWechat}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学员数量：</label>
            <div class="col-sm-8">
                <input name="studentCount" th:field="*{studentCount}" class="form-control" type="number" required number="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">会员数量：</label>
            <div class="col-sm-8">
                <input name="memberCount" th:field="*{memberCount}" class="form-control" type="number" required number="true">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学校健康度：</label>
            <div class="col-sm-8">
                <input name="healthDegree" th:field="*{healthDegree}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: jquery-cxselect-js"/>
<script th:inline="javascript">
    var prefix = ctx + "teaching/school";
    $("#form-school-edit").validate({
        focusCleanup: true
    });

    // 通过默认url获取
    var urlChina = '/system/cityData/jsonData';
    $.cxSelect.defaults.url = urlChina;
    $.cxSelect.defaults.jsonValue = "code";
    $('#element1').cxSelect({
        selects: ['province', 'city', 'area'],
        nodata: 'none'
    });

    function submitHandler() {
        if ($.validate.form()) {
            let data = $('#form-school-edit').serializeArray();
            let provinceName = $("select[name='provinceCode'] option:checked").text();
            let cityName = $("select[name='cityCode'] option:checked").text();
            let areaName = $("select[name='areaCode'] option:checked").text();
            data.push({"name": "provinceName", "value": provinceName})
            data.push({"name": "cityName", "value": cityName})
            data.push({"name": "areaName", "value": areaName})
            $.operate.save(prefix + "/edit", data);
        }
    }

    $("input[name='joinTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='allottedTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
</script>
</body>
</html>
